package com.github.fashionbrot.controller;


import com.github.fashionbrot.entity.TableColumnEntity;
import com.github.fashionbrot.mapper.TableMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequiredArgsConstructor
public class TableController {

    final TableMapper tableMapper;

    @ResponseBody
    @GetMapping("queryColumn")
    public List<TableColumnEntity> queryColumnList(String tableName){
        String sql="pragma table_info("+tableName+")";
        List<TableColumnEntity> tableColumnEntities = tableMapper.queryColumns(sql);
        return tableColumnEntities;
    }


    @ResponseBody
    @GetMapping("queryTable")
    public List<String> queryTable(){
        List<String> tables = tableMapper.queryTables();
        return tables;
    }

}
